package org.dromara.wms.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.web.core.BaseService;
import org.dromara.wms.service.WmsStockService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.wms.domain.WmsScheduleLine;
import org.dromara.wms.service.WmsScheduleLineService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 生产计划排程
 *
 * @author wenrui Su
 * @date 2024-05-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/scheduleLine")
public class WmsScheduleLineController extends BaseService {

  private final WmsScheduleLineService wmsScheduleLineService;

/**
 * 查询生产计划排程列表
 */
@SaCheckPermission("wms:scheduleLine:list")
@GetMapping("/list")
  public TableDataInfo<WmsScheduleLine> list(WmsScheduleLine bo, PageQuery pageQuery) {
    return wmsScheduleLineService.queryPageList(bo, pageQuery);
  }

  /**
   * 导出生产计划排程列表
   */
  @SaCheckPermission("wms:scheduleLine:export")
  @Log(title = "生产计划排程", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(WmsScheduleLine bo, HttpServletResponse response) {
    List<WmsScheduleLine> list = wmsScheduleLineService.queryList(bo);
    ExcelUtil.exportExcel(list, "生产计划排程", WmsScheduleLine. class,response);
  }

  /**
   * 获取生产计划排程详细信息
   *
   * @param lineId 主键
   */
  @SaCheckPermission("wms:scheduleLine:query")
  @GetMapping("/{lineId}")
  public R<WmsScheduleLine> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long lineId) {
    return R.ok(wmsScheduleLineService.queryById(lineId));
  }

  /**
   * 新增生产计划排程
   */
  @SaCheckPermission("wms:scheduleLine:add")
  @Log(title = "生产计划排程", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsScheduleLine bo) {
    return toAjax(wmsScheduleLineService.insertByBo(bo));
  }

  /**
   * 生产计划排程
   */
  @SaCheckPermission("wms:scheduleLine:edit")
  @Log(title = "生产计划排程", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsScheduleLine bo) throws WmsStockService.emptyException {
    return toAjax(wmsScheduleLineService.updateByBo(bo));
  }

  /**
   * 删除生产计划排程
   *
   * @param lineIds 主键串
   */
  @SaCheckPermission("wms:scheduleLine:remove")
  @Log(title = "生产计划排程", businessType = BusinessType.DELETE)
  @DeleteMapping("/{lineIds}")
  public R<Void> remove(@NotEmpty(message = "主键不能为空")
                        @PathVariable Long[] lineIds) {
    return toAjax(wmsScheduleLineService.deleteWithValidByIds(List.of(lineIds), true));
  }
}
